package com.wyl.auth.controller;

import cn.hutool.core.lang.tree.Tree;
import com.wyl.auth.dto.SysMenuDto;
import com.wyl.auth.dto.SysRoleMenuDto;
import com.wyl.auth.req.SysMenuReq;
import com.wyl.auth.service.SysMenuService;
import com.wyl.auth.vo.SysMenuVo;
import com.wyl.common.CommonPage;
import com.wyl.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @Description 菜单表
* @Author WuYiLong
* @Date 2024-12-02
*/
@Api(tags = "系统菜单")
@RestController
@RequestMapping("sysMenu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @ApiOperation(value = "保存")
    @PostMapping(value = "save")
    public ResponseData<Long> save(@RequestBody SysMenuDto sysMenuDto) {
        return ResponseData.create().getSuccessInstance(sysMenuService.save(sysMenuDto));
    }

    @ApiOperation(value = "分页")
    @PostMapping(value = "page")
    public ResponseData<CommonPage<SysMenuVo>> page(@RequestBody SysMenuReq req) {
        return ResponseData.getSuccessInstance(sysMenuService.page(req));
    }

    @ApiOperation(value = "删除")
    @PostMapping(value = "deleteByIds")
    public ResponseData deleteByIds(@RequestBody List<Long> ids) {
        sysMenuService.deleteByIds(ids);
        return ResponseData.getSuccess();
    }

    @ApiOperation(value = "树形菜单")
    @PostMapping(value = "treeSysMenu")
    public ResponseData<List<Tree<Long>>> treeSysMenu(@RequestBody SysMenuReq req) {
        return ResponseData.getSuccessInstance(sysMenuService.treeSysMenu(req));
    }

    @ApiOperation(value = "父级菜单")
    @GetMapping(value = "listCatalog")
    public ResponseData<List<Tree<Long>>> listCatalog() {
        return ResponseData.getSuccessInstance(sysMenuService.listCatalog());
    }


}
